{template 'web/_header'}
{template 'tabs'}

{if $operation=='display'}
<div class="panel panel-info">
    <div class="panel-heading">筛选</div>
    <div class="panel-body">
        <form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
            <input type="hidden" name="c" value="site" />
            <input type="hidden" name="a" value="entry" />
            <input type="hidden" name="m" value="ewei_shop" />
            <input type="hidden" name="do" value="plugin" />
            <input type="hidden" name="p" value="commission" />
            <input type="hidden" name="method" value="apply" />
            <input type="hidden" name="op" value="display" />
            <input type="hidden" name="status" value="{$status}" />
           
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">按时间</label>
                     <div class="col-sm-2">
                       <select name='timetype' class='form-control'>
                          <option value=''>不搜索</option>
                           {if $status>=1}<option value='applytime' {if $_GPC['timetype']=='applytime'}selected{/if}>申请时间</option>{/if}
                           {if $status>=2}<option value='checktime' {if $_GPC['timetype']=='checktime'}selected{/if}>审核时间</option>{/if}
                           {if $status>=3}<option value='paytime' {if $_GPC['timetype']=='paytime'}selected{/if}>打款时间</option>{/if}
                       </select> 
                     </div>
                    
                    <div class="col-sm-7 col-lg-9 col-xs-12">
                     
                        {php echo tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d  H:i', $endtime)),true);}
                    </div>
                </div>
                  <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">提现单号</label>
                <div class="col-sm-8 col-lg-9 col-xs-12">
                    <input type="text" class="form-control"  name="applyno" value="{$_GPC['applyno']}"/> 
                </div> 
            </div>
                  <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">会员信息</label>
                <div class="col-sm-8 col-lg-9 col-xs-12">
                    <input type="text" class="form-control"  name="realname" value="{$_GPC['realname']}" placeholder="可搜索昵称/姓名/手机号"/> 
                </div>
            </div>
 
             <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">等级</label>
                <div class="col-sm-8 col-lg-9 col-xs-12">
                    <select name='agentlevel' class='form-control'>
                        <option value=''>全部分销商</option>
                         {loop $agentlevels $level}
                        <option value='{$level['id']}' {if $_GPC['agentlevel']==$level['id']}selected{/if}>{$level['levelname']}</option>
                        {/loop}
                    </select>
                </div>
                <div class="col-sm-3 col-lg-2">
                    <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                    <button type="submit" name="export" value="1" class="btn btn-primary">导出Excel</button>
                </div>
            </div>
 
        </form>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">总数：{$total}</div>
    <div class="panel-body">
        <table class="table table-hover">
            <thead class="navbar-inner">
                <tr>
                    <th style='width:210px;'>提现单号</th>
                    <th style='width:120px;'>粉丝</th>
                    <th style='width:120px;'>姓名</th>
                    <th style='width:120px;'>手机号码</th>
                    <th style='width:120px;'>分销等级</th>
                    <th style='width:100px;'>提现方式</th>
                    <th style='width:100px;'>申请佣金</th>
                     {if $status>=1}
                    <th style='width:200px;'>申请时间</th>
                    {/if}
                    {if $status>=2}
                    <th style='width:200px;'>审核时间</th>
                    {/if}
                    {if $status>=3}
                    <th style='width:200px;'>打款时间</th>
                    {/if}
                       {if $status==-1}
                    <th style='width:200px;'>设置无效时间</th>
                    {/if}
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $row}
                <tr>
                    <td>{$row['applyno']}</td>
                    <td><img src='{$row['avatar']}' style='width:30px;height:30px;padding1px;border:1px solid #ccc' /> {$row['nickname']}</td>
                    <td>{$row['realname']}</td>
                    <td>{$row['mobile']}</td>
                    <td>{if empty($row['levelname'])}{php echo empty($this->set['levelname'])?'普通等级':$this->set['levelname']}{else}{$row['levelname']}{/if}</td>
                    <td>{if empty($row['type'])}余额{else}微信{/if}</td>
                    <td>{$row['commission']}</td>
                     {if $status>=1}
                     <td>{php echo date('Y-m-d H:i',$row['applytime'])}</td>
                     {/if}
                     {if $status>=2}
                    <td>{php echo date('Y-m-d H:i',$row['checktime'])}</td>
                     {/if}
                    {if $status>=3}
                    <td>{php echo date('Y-m-d H:i',$row['paytime'])}</td>
                    {/if}
                        {if $status==-1}
                    <td>{php echo date('Y-m-d H:i',$row['invalidtime'])}</td>
                    {/if}
                     <td>
                        <a class='btn btn-default' href="{php echo $this->createPluginWebUrl('commission/apply/detail',array('id' => $row['id']));}">详情</a>		
                    </td>
                </tr>
                {/loop}
            </tbody>
        </table>
        {$pager}
    </div>
</div>
{else if $operation=='detail'}

<form {ifp 'commission.apply.check|commission.apply.pay|commission.apply.cancel'}action="" method='post'{/if} class='form-horizontal'>
    <input type="hidden" name="id" value="{$member['id']}">
    <input type="hidden" name="op" value="detail">
    <input type="hidden" name="c" value="site" />
    <input type="hidden" name="a" value="entry" />
    <input type="hidden" name="m" value="ewei_shop" />
    <input type="hidden" name="p" value="commission" />
    <input type="hidden" name="method" value="apply" />
    <input type="hidden" name="op" value="detail" />
    <input type="hidden" name="id" value="{$apply['id']}" />
    <div class="panel panel-default">
        <div class='panel-heading'>
            提现者信息
        </div>
    <div class='panel-body'>
    <div style='height:auto;width:120px;float:left;'>
         <img src='{$member['avatar']}' style='width:100px;height:100px;border:1px solid #ccc;padding:1px' />
    </div>
    <div style='float:left;height:auto;overflow: hidden'>
        <p><b>昵称:</b> {$member['nickname']}    <b>姓名:</b> {$member['realname']}  <b>手机号:</b> {$member['mobile']}    <b>微信号:</b> {$member['weixin']}</p>
        <p><b>分销等级:</b>  {$agentLevel['levelname']} (
         {if $this->set['level']>=1}一级比例: <span style='color:blue'>{$agentLevel['commission1']}%</span>{/if}
         {if $this->set['level']>=2}二级比例: <span style='color:blue'>{$agentLevel['commission2']}%</span>{/if}
         {if $this->set['level']>=3}三级比例: <span style='color:blue'>{$agentLevel['commission3']}%</span>{/if}
        )</p>
        <p>
        <b>下级:</b> 总共 <span style='color:red'>{$member['agentcount']}</span> 人 
        {if $this->set['level']>=1}<b>一级:</b><span style='color:red'>{$member['level1']}</span>  人{/if}  
        {if $this->set['level']>=2}<b>二级:</b> <span style='color:red'>{$member['level2']}</span>  人{/if} 
        {if $this->set['level']>=3}<b>三级: </b><span style='color:red'>{$member['level3']}</span> 人{/if}
                点击:  <span style='color:red'>{$member['clickcount']}</span> 次 
       
                <b>累计佣金: </b><span style='color:red'>{$member['commission_total']}</span> 元  
                <b>待审核佣金: </b><span style='color:red'>{$member['commission_apply']}</span> 元  
                <b>待打款佣金: </b><span style='color:red'>{$member['commission_check']}</span> 元  
                <b>结算期佣金: </b><span style='color:red'>{$member['commission_lock']}</span> 元  </p>
      <p>
                <b>申请佣金: </b><span style='color:red'>{$apply['commission']}</span> 元  
                <b>打款方式: </b>
                {if empty($apply['type'])}
                <span class='label label-primary'>余额</span>
                {else}
                <span class='label label-success'>微信</span>
                {/if}

      </p>
      <p>
                <b>状态: </b>
                {if $apply['status']==1}
                <span class='label label-primary'>申请中</span>
                {else if $apply['status']==2}
                <span class='label label-success'>审核完毕，准备打款</span>
                {else if $apply['status']==3}
                <span class='label label-warning'>已打款</span>
                {/if}
                {if $apply['status']>=1}<b>申请时间: </b> {php echo date('Y-m-d H:i', $apply['applytime'])}{/if}
                 {if $apply['status']>=2}<b>审核时间: </b> {php echo date('Y-m-d H:i', $apply['checktime'])}{/if}
                  {if $apply['status']>=3}<b>打款时间: </b> {php echo date('Y-m-d H:i', $apply['paytime'])}{/if}
      </p>
    </div>
        </div>
 
        <div class='panel-heading'>
            提现申请订单信息 共计 <span style="color:red; ">{$totalcount}</span> 个订单 , 金额共计 <span style="color:red; ">{$totalmoney}</span> 元 佣金总计 <span style="color:red; ">{$totalcommission}</span> 元
            
            <a href="javascript:;" onclick="checkall(true)" class="btn btn-success">批量审核通过</a>
            <a href="javascript:;" onclick="checkall(false)" class="btn btn-danger">批量审核不通过</a>
            <button type='submit' name="export" value="1" class="btn btn-primary">导出Excel</button>
        </div>
        <div class='panel-body'>
            <table class="table table-hover">
                       <thead class="navbar-inner">
                           <tr>
                               <th>订单号</th>
                               <th>总金额</th>
                               <th>商品金额</th>
                               <th>运费</th>
                               <th>付款方式</th>
                           
                               <th>下单时间</th>
                           </tr>
                       </thead>
                       <tbody>
                           {loop $list $row}
                           <tr  style="background: #eee">
                               <td><a href="{php echo $this->createWebUrl('order', array('op' => 'display','keyword'=>$row['ordersn']))}" target="_blank">{$row['ordersn']}</a></td>
                               <td>{$row['price']}</td>
                               <td>{$row['goodsprice']}</td>
                               <td>{$row['dispatchprice']}</td>
                               <td>{if $row['paytype'] == 1}
                                          <span class="label label-danger">余额支付</span>
                                             {elseif $row['paytype'] == 11}
                                          <span class="label label-default">后台付款</span>
                                      {elseif $row['paytype'] == 21}
                                          <span class="label label-success">在线支付</span>
                                          {elseif $row['paytype'] == 22}
                                          <span class="label label-danger">支付宝支付</span>
                                            {elseif $row['paytype'] == 22}
                                          <span class="label label-primary">银联支付</span>
                                      {elseif $row['paytype'] == 3}
                                      <span class="label label-primary">货到付款</span>
                                    {/if}
                               </td>
              
                               <td>{php echo date('Y-m-d H:i',$row['createtime'])}</td>   
                           </tr>	
                           <tr >

                               <td colspan="6">
                                   <table width="100%">
                    <thead class="navbar-inner">
                                             <tr>
                                                 <th style='width:60px;'>商品</th>
                                                 <th></th>
                                                 <th>单价</th>
                                                 <th>数量</th>
                                                 <th>总价</th>
                                                 <th>佣金</th>
                                                
                                             </tr>
                                         </thead>
                                       <tbody>
                                           {loop $row['goods'] $g}
                                           <tr>
                                               <td style='height:60px;'><img src="{php echo tomedia($g['thumb'])}" style="width: 50px; height: 50px;border:1px solid #ccc;padding:1px;"></td>
                                               <td><span>{$g['title']}</span><br/><span>{$g['optionname']}</span>
                                               </td>
                                               <td>原价: {php echo $g['price']/$g['total']}<br/>折扣后:{php echo $g['realprice']/$g['total']}</td>
                                               <td>{$g['total']}</td>
                                               <td><strong>原价:{php echo round($g['price'],2)}<br/>折扣后:{php echo round($g['realprice'],2)}</strong></td>
                                               <td>
                                                   {if $this->set['level']>=1 && $row['level']==1}<p>
                                                   <div class='input-group'>
                                                       <span class='input-group-addon'>一级佣金</span>
                                                     <span class='input-group-addon' style='background:#fff;width:80px;'>{$g['commission1']}</span>
                                                       <span class='input-group-addon'>状态</span>    
                                                       <span class='input-group-addon' style='background:#fff'>
                                                             {if $g['status1']==-1}
                                                                <span class='label label-default'>未通过</span>
                                                                {elseif $g['status1']==1}

                                                                <label class='radio-inline'><input type='radio'  class='status1' value='-1'  name="status1[{$g['id']}]" /> 不通过</label>
                                                                <label class='radio-inline'><input type='radio'  value='2'   name="status1[{$g['id']}]"  /> 通过</label>

                                                                {elseif $g['status1']==2}
                                                                <span class='label label-success'>通过</span>
                                                                {elseif $g['status1']==3}
                                                                <span class='label label-warning'>已打款</span>
                                                                {/if}
                                                          </span>
                                                        <span class='input-group-addon'>备注</span>  
                                                        <input type='text' class='form-control' name='content1[{$g['id']}]' style='width:200px;' value="{$g['content1']}">
                                                   </div></p>
                                                   {/if}
                                                   
                                                   {if $this->set['level']>=2  && $row['level']==2}<p>
                                              
                                                   <div class='input-group'>
                                                       <span class='input-group-addon'>二级佣金</span>
                                                       <span class='input-group-addon' style='background:#fff;width:80px;'>{$g['commission2']}</span>
                                                       <span class='input-group-addon'>状态</span>    
                                                       <span class='input-group-addon' style='background:#fff'>
                                                             {if $g['status2']==-1}
                                                                <span class='label label-default'>未通过</span>
                                                                {elseif $g['status2']==1}

                                                                <label class='radio-inline'><input type='radio' class='status2' value='-1'  name="status2[{$g['id']}]" /> 不通过</label>
                                                                <label class='radio-inline'><input type='radio'  value='2'  name="status2[{$g['id']}]"  /> 通过</label>

                                                                {elseif $g['status2']==2}
                                                                <span class='label label-success'>通过</span>
                                                                {elseif $g['status2']==3}
                                                                <span class='label label-warning'>已打款</span>
                                                                {/if}
                                                          </span>
                                                        <span class='input-group-addon'>备注</span>  
                                                        <input type='text' class='form-control' name='content2[{$g['id']}]' style='width:200px;' value="{$g['content2']}">
                                                   </div>
                                               </p>
                                                   {/if}
                                                   {if $this->set['level']>=2  && $row['level']==3}<p>
                                                    
                                                   <div class='input-group'>
                                                       <span class='input-group-addon'>三级佣金</span>
                                                      <span class='input-group-addon' style='background:#fff;width:80px;'>{$g['commission3']}</span>
                                                       <span class='input-group-addon'>状态</span>    
                                                       <span class='input-group-addon' style='background:#fff'>
                                                             {if $g['status3']==-1}
                                                                <span class='label label-default'>未通过</span>
                                                                {elseif $g['status3']==1}

                                                                <label class='radio-inline'><input type='radio' class='status3' value='-1' name="status3[{$g['id']}]" /> 不通过</label>
                                                                <label class='radio-inline'><input type='radio' value='2' name="status3[{$g['id']}]"  /> 通过</label>

                                                                {elseif $g['status3']==2}
                                                                <span class='label label-success'>通过</span>
                                                                {elseif $g['status3']==3}
                                                                <span class='label label-warning'>已打款</span>
                                                                {/if}
                                                          </span>
                                                        <span class='input-group-addon'>备注</span>  
                                                        <input type='text' class='form-control' name='content3[{$g['id']}]' style='width:200px;'  value="{$g['content3']}">
                                                   </div>
                                                        </p>
                                                   {/if}
                                               </td>
                                           </tr>
                                           {/loop}
                                       </tbody></table>	   
                               </td></tr>	
                       {/loop}
                   </table>
        </div>

  {if $apply['status']==2}
     <div class='panel-heading'>
            打款信息
     </div>
    <div class='panel-body'>
        此次佣金总额:  <span style='color:red'>{$totalcommission}</span> 元    应该打款：<span style='color:red'>{$totalpay}</span> 元 
    </div>
  {/if}
  
   {if $apply['status']==3}
     <div class='panel-heading'>
            打款信息
     </div>
    <div class='panel-body'>
         此次佣金总额:  <span style='color:red'>{$totalcommission}</span> 元    实际打款：<span style='color:red'>{$totalpay}</span> 元 
    </div>
  {/if}
  
            </div>  
        <div class="form-group col-sm-12">
        {if $apply['status']==1}
        {ifp 'commission.apply.check'}
        <input type="submit" name="submit_check" value="提交审核" class="btn btn-primary col-lg-1" onclick='return check()'/>
        {/if}
        {/if}
        
         {if $apply['status']==2}
        
         {ifp 'commission.apply.cancel'}
        <input type="submit" name="submit_cancel" value="重新审核" class="btn btn-default col-lg-1"  onclick='return cancel()'/>
        {/if}
            {ifp 'commission.apply.pay'}
              {if empty($apply['type'])}
             <input type="submit" name="submit_pay" value="打款到余额账户" class="btn btn-primary col-lg-1"  style='margin-left:10px;' onclick='return pay_credit()'/>
              {else}
             <input type="submit" name="submit_pay" value="打款到微信钱包" class="btn btn-primary col-lg-1" style='margin-left:10px;' onclick='return pay_weixin()'/>
             {/if}
             {/if}
        {/if}
        {if $apply['status']==-1}
           {ifp 'commission.apply.cancel'}
            <input type="submit" name="submit_cancel" value="重新审核" class="btn btn-default col-lg-1"  onclick='return cancel()'/>
            {/if}
     
        {/if}
        
        <input type="button" class="btn btn-default" name="submit" onclick="history.go(-1)" value="返回" style='margin-left:10px;' />
        <input type="hidden" name="token" value="{$_W['token']}" />
    </div>
</form>
<script language='javascript'>
function checkall(ischeck){
 var val =  ischeck?2:-1;
 
     $('.status1,.status2,.status3').each(function(){
        $(this).closest('.input-group-addon').find(":radio[value='" + val + "']").get(0).checked = true;
     });
}
    function check(){
    var pass  = true;
     $('.status1,.status2,.status3').each(function(){
       if( !$(this).get(0).checked && !$(this).parent().next().find(':radio').get(0).checked){
         Tip.focus( $(this),'请选择审核状态!' );
         pass = false;
         return false;
       }
     });
     if(!pass){ 
          return false;
     }
     return confirm('确认已核实成功并要提交?\r\n(提交后还可以撤销审核状态, 申请将恢复到申请状态)');
    }
        function cancel(){
           return confirm('确认撤销审核?\r\n( 所有状态恢复到申请状态)'); 
        }
        function pay_credit(){
           return confirm('确认打款到此用户的余额账户?');  
        }
        function pay_weixin(){
            return confirm('确认打款到此用户的微信钱包?');     
        }
</script>
{/if}
{template 'common/footer'}